package com.skt.config;

import java.util.concurrent.TimeUnit;

/**
 * 缓存键常量配置类
 * 统一管理系统中所有的Redis缓存键和过期时间配置
 */
public class CacheConstants {

    // ========== 缓存过期时间配置 ==========

    /** 用户实体信息缓存过期时间（30分钟） */
    public static final long USER_ENTITY_EXPIRE_MINUTES = 30L;
    public static final TimeUnit USER_ENTITY_EXPIRE_UNIT = TimeUnit.MINUTES;

    /** 用户会话信息缓存过期时间（24小时） */
    public static final long USER_SESSION_EXPIRE_HOURS = 24L;
    public static final TimeUnit USER_SESSION_EXPIRE_UNIT = TimeUnit.HOURS;

    /** 登录失败计数缓存过期时间（5分钟） */
    public static final long LOGIN_FAIL_COUNT_EXPIRE_MINUTES = 5L;
    public static final TimeUnit LOGIN_FAIL_COUNT_EXPIRE_UNIT = TimeUnit.MINUTES;

    /** 分布式锁默认过期时间（30秒） */
    public static final long DISTRIBUTED_LOCK_EXPIRE_SECONDS = 30L;
    public static final TimeUnit DISTRIBUTED_LOCK_EXPIRE_UNIT = TimeUnit.SECONDS;

    /** 审计日志缓存过期时间（7天） */
    public static final long AUDIT_LOG_EXPIRE_DAYS = 7L;
    public static final TimeUnit AUDIT_LOG_EXPIRE_UNIT = TimeUnit.DAYS;

    // ========== 业务限制相关常量 ==========

    /** 单个IP最大登录尝试次数 */
    public static final int MAX_LOGIN_ATTEMPTS_PER_IP = 10;

    /** 单个用户最大登录失败次数 */
    public static final int MAX_LOGIN_FAILURES_PER_USER = 5;

    /** 账户锁定持续时间（分钟） */
    public static final int LOCK_DURATION_MINUTES = 30;

    /** 分布式锁等待时间（秒） */
    public static final long DISTRIBUTED_LOCK_WAIT_SECONDS = 3L;

    // ========== 统一缓存键前缀（只保留一套） ==========

    // 用户相关缓存键
    public static final String USER_ENTITY_KEY_PREFIX = "user:entity:";
    public static final String USER_DETAIL_KEY_PREFIX = "user:detail:";
    public static final String USER_INFO_KEY_PREFIX = "user:info:";
    public static final String USER_SESSION_KEY_PREFIX = "user:session:";

    // 登录状态相关
    public static final String USER_LOGIN_STATUS_KEY_PREFIX = "user_login_status:";
    public static final String USER_ONLINE_STATUS_KEY_PREFIX = "user_online_status:";
    public static final String USER_LAST_LOGIN_KEY_PREFIX = "user_last_login:";

    // 令牌相关
    public static final String USER_TOKEN_KEY_PREFIX = "user_token:";
    public static final String USER_TOKENS_KEY_PREFIX = "user_tokens:";
    public static final String TOKEN_USER_KEY_PREFIX = "token_user:";
    public static final String ACCESS_TOKEN_KEY_PREFIX = "access_token:";
    public static final String REFRESH_TOKEN_KEY_PREFIX = "refresh_token:";
    public static final String TOKEN_BLACKLIST_KEY_PREFIX = "token_blacklist:";
    public static final String REFRESH_TOKEN_BLACKLIST_KEY_PREFIX = "refresh_token_blacklist:";

    // 会话相关
    public static final String USER_SESSIONS_KEY_PREFIX = "user_sessions:";

    // 分布式锁相关
    public static final String REGISTER_LOCK_KEY_PREFIX = "register_lock:";
    public static final String LOGIN_LOCK_KEY_PREFIX = "login_lock:";
    public static final String LOGOUT_LOCK_KEY_PREFIX = "logout_lock:";
    public static final String REFRESH_LOCK_KEY_PREFIX = "refresh_lock:";
    public static final String UPDATE_PROFILE_LOCK_KEY_PREFIX = "update_user_profile_lock:";

    // 风控相关
    public static final String LOGIN_IP_LIMIT_KEY_PREFIX = "login_ip_limit:";
    public static final String LOGIN_FAIL_COUNT_KEY_PREFIX = "login_fail_count:";
    public static final String IP_LOCK_KEY_PREFIX = "ip_lock:";
    public static final String ACCOUNT_LOCK_KEY_PREFIX = "account_lock:";
    public static final String LOGIN_DEVICE_KEY_PREFIX = "login_device:";
    public static final String USER_DEVICES_KEY_PREFIX = "user_devices:";

    // 审计日志相关
    public static final String LOGIN_AUDIT_KEY_PREFIX = "login_audit:";
    public static final String LOGOUT_AUDIT_KEY_PREFIX = "logout_audit:";
    public static final String REFRESH_TOKEN_AUDIT_KEY_PREFIX = "refresh_token_audit:";
    public static final String UPDATE_PROFILE_AUDIT_KEY_PREFIX = "update_profile_audit:";

    // 业务相关
    public static final String USER_EXISTS_KEY_PREFIX = "user_exists:";
    public static final String LOGIN_METRICS_KEY_PREFIX = "login_metrics:";
    public static final String REFRESH_TOKEN_SESSION_KEY_PREFIX = "refresh_token_session:";
    public static final String DEVICE_FINGERPRINT_KEY_PREFIX = "device_fingerprint:";

    // 设备相关
    public static final String USER_DEVICE_INFO_KEY_PREFIX = "user:device:";

    // ========== 购物车相关缓存键（新增） ==========
    public static final String CART_KEY_PREFIX = "cart:user:";
    public static final String CART_ITEM_KEY_PREFIX = "cart:item:";
    public static final String CART_LOCK_KEY_PREFIX = "cart:lock:";

    /**
     * 商品基本信息缓存Key
     * 格式：costume:info:{costumeId}
     * 存储：Costume对象序列化数据
     * 过期时间：2小时（商品信息相对稳定）
     */
    public static final String COSTUME_INFO_KEY_PREFIX = "costume:info:";

    /**
     * 商品库存缓存Key
     * 格式：costume:stock:{costumeId}
     * 存储：库存数量（Integer）
     * 过期时间：30分钟（库存变化频繁）
     */
    public static final String COSTUME_STOCK_KEY_PREFIX = "costume:stock:";

    /**
     * 商品价格快照Key
     * 格式：costume:price:{costumeId}
     * 存储：价格快照（BigDecimal）
     * 过期时间：1小时（价格可能变动）
     */
    public static final String COSTUME_PRICE_KEY_PREFIX = "costume:price:";

    /**
     * 商品状态缓存Key
     * 格式：costume:status:{costumeId}
     * 存储：商品状态（1-可租，2-已租等）
     * 过期时间：1小时
     */
    public static final String COSTUME_STATUS_KEY_PREFIX = "costume:status:";

    /** 购物车缓存过期时间（30天） */
    public static final long CART_EXPIRE_DAYS = 30L;
    public static final TimeUnit CART_EXPIRE_UNIT = TimeUnit.DAYS;


    private CacheConstants() {
        // 防止实例化
    }
}